import * as api from './api';
import { UserPageQuery, CrudExpose, CrudOptions, CreateCrudOptionsProps, CreateCrudOptionsRet, dict } from '@fast-crud/fast-crud';
import { commonCrudConfig } from "/@/utils/commonCrud";
import { ElMessage } from 'element-plus';
import { ref } from 'vue';
import drawerTitle from './index.vue'

export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
    
    const pageRequest = async (query: UserPageQuery) => {
        // return await api.GetList(query);
    };
    return {
        crudOptions: {  
            request: {
                pageRequest,
                autoload: false 
            },
            actionbar: {
                buttons: { 
                    add: {
                        show: false,
                    },
                    upload: {
                        text: '添加',
                        type: 'primary',
                        click: () => {
                            // 在这里实现上传功能的逻辑
                            // console.log('上传功能被点击');
                        },
                    },
                    merge: {
                        text: '删除',
                        type: 'danger',
                        click: () => {
                            // 在这里实现合并功能的逻辑
                            // console.log('合并功能被点击');
                        },
                    },
                },
            },
            rowHandle: {
                show: false,  
            },
            columns: {
                cycle: { // 时间周期字段
                    title: '时间周期',
                    search: { 
                        show: true, // 显示在搜索条件
                        // 可配置更多搜索参数
                        col: { span: 6 },
                        component: {
                            name: 'el-select', // 使用下拉选择器
                            options: [ // 选项示例
                                { label: '日线', value: 'day' },
                                { label: '周线', value: 'week' },
                                { label: '月线', value: 'month' }
                            ]
                        }
                    },
                    column: {
                        show: false // 不在表格列中显示
                    },
                    form: {
                        show: false // 不在表单中显示（如果需要）
                    }
                },
                _index: {
                    title: '序号',
                    form: { show: false },
                    column: {
                        align: 'center',
                        width: '70px',
                        columnSetDisabled: true,
                        formatter: (context) => {
                            let index = context.index ?? 1;
                            let pagination = crudExpose!.crudBinding.value.pagination;
                            return ((pagination!.currentPage ?? 1) - 1) * pagination!.pageSize + index + 1;
                        },
                    },
                },
                time: {
                    title: '时间',
                    type: 'datetime',
                    column: {
                        minWidth: 150,
                    },
                    form: {
                        disabled: true,
                    },
                },
                open: {
                    title: '开盘价',
                    type: 'float',
                    column: {
                        minWidth: 90,
                    },
                    form: {
                        disabled: true,
                    },
                    defaultValue: 1,
                },
                high: {
                    title: '最高价',
                    type: 'float',
                    column: {
                        minWidth: 90,
                    },
                    search: {
                        show: false
                    },
                    form: {
                        disabled: false,
                    },
                },
                low: {
                    title: '最低价',
                    type: 'float',
                    column: {
                        minWidth: 90,
                    },
                    search: {
                        show: false
                    },
                    form: {
                        disabled: true,
                    },
                },
                close: {
                    title: '收盘价',
                    type: 'float',
                    column: {
                        minWidth: 90,
                    },
                    form: {
                        disabled: true,
                    },
                    defaultValue: 0,
                },
                volume: {
                    title: '成交量',
                    type: 'float',
                    column: {
                        minWidth: 90,
                    },
                    form: {
                        disabled: true,
                    },
                    defaultValue: 0,
                },
            },
        },
    };
};